package com.rp.security.extend;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.rp.system.dao.UserDao;
import com.rp.system.po.User;

@Service
public class CustomUserDetailsService implements UserDetailsService {
	
	private static Logger log = Logger.getLogger(CustomUserDetailsService.class);
	
	@Autowired
	private UserDao userDao;

	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		log.info("加载登陆用户的相关信息");
		User user = userDao.getUserByUsername(username);
		if (user == null) {
			throw new UsernameNotFoundException("找不到相关用户");
		}
		
		return user;
	}
	
}
